home *** CD-ROM | disk | FTP | other *** search
- #include <Traps.h>
- #include <A4Stuff.h>
- #include <LowMem.h>
- /*
- #include "6502.h"
- #include "global.h"
-
- #include "interpret.h"
- */
-
- UniversalProcPtr gOldMixedModeMagic;
- Handle gInterpreterCode;
-
- asm void MyMixedModeMagicPatch(void);
- pascal void InstallGlobals(void);
- Ptr gRom6502 = nil;
- SInt32 gCallBack=nil;
-
- #define kRegsToSave 14 // number of registers pushed on the stack
- // stack spac registers take up
- #define StackRegSize (kRegsToSave * sizeof(long))
- #define kNEWCPU 0x03 // ISA / RTA of our FAKE CPU
-
- void main(void)
- {
- Handle h; // Handle to resource
- UniversalProcPtr myPatch;
- OSErr err;
- THz theZone;
-
- EnterCodeResource(); // Get globals
-
- theZone = GetZone();
- SetZone(SystemZone());
-
- h = GetResource('INIT', 0); // Get the resource
- HLock(h);
- DetachResource(h); // Detach
- // Get old Trap
-
- h = GetResource('ROMA', 128); // Get 6502 ROM
- if (h) {
- HLock(h);
- DetachResource(h);
- gRom6502 = *h;
- }
-
- err = NewGestaltValue('6502', (SInt32)& gCallBack);
-
- gInterpreterCode = GetResource('INTP', 128);
- if (!gInterpreterCode) {
- DebugStr("\pYou bettter do an es");
- HLock(gInterpreterCode);
- }
- DetachResource(gInterpreterCode);
- gInterpreterCode = (Handle) *gInterpreterCode;
-
- gOldMixedModeMagic = NGetTrapAddress(_MixedModeMagic, (_MixedModeMagic & 0x0800) ? ToolTrap : OSTrap);
-
- InstallGlobals(); // Instal globals for patch
-
- myPatch = NewRoutineDescriptor((ProcPtr)MyMixedModeMagicPatch, 0, GetCurrentArchitecture);
-
- // Set new trap
- NSetTrapAddress(myPatch, _MixedModeMagic, (_MixedModeMagic & 0x0800) ? ToolTrap : OSTrap);
-
- SetZone(theZone);
-
- ExitCodeResource(); // Done fooling around with globals
- }
-
- asm void MyMixedModeMagicPatch(void)
- {
- bra.s start // branch to real start
-
- entry static InstallGlobals // entry point to install globals
-
- InstallGlobals:
- lea oldMagic, a0 // get address to save globals
- move.l gOldMixedModeMagic,(a0) // save old mixmodeaddress
- lea interpret, a0
- move.l gInterpreterCode,(a0)
- lea gCallBack,a1
- lea callBack,a0
- move.l a1,(a0)
- rts // bye
-
- start:
- movem.l a0-a6/d0-d6,-(sp) // save all registers
-
- move.l StackRegSize(sp),d0 // get stack
- subi.l #2,d0 // subtract 2
- movea.l d0,a0 // a0 now contains RoutineDescriptorPtr
-
- cmpi.w #0,10(a0) // Number of routine descriptors
- bne.s normalMixedMode // We only use 1 routine
-
- cmpi.b #kNEWCPU, 17(a0) // see if it is our CPU
- bne.s normalMixedMode // no
-
- add.l #0x20,a0 // A0 now points to the code
- move.l interpret,a2 // a2 points to interpreter
- move.l callBack,a1 // a1 is a Ptr to a callback function
- move.l (a1),a1 // deref
- jsr (a2) // InterPret the code
-
- movem.l (sp)+,a0-a6/d0-d6 // restore regs
- addq.l #4,sp // This makes it work (Not sure Why?????)
- rts
-
- normalMixedMode:
- movem.l (sp)+,a0-a6/d0-d6 // normal MixedModeMagic
- move.l oldMagic,-(sp) // put original trap address on stack
- rts // Bye!
-
- oldMagic: dc.l 0 // storage for globals
- result: dc.l 0
- interpret: dc.l 0
- callBack: dc.l 0
-
- }
-